using System;
using System.Data;
 

/// <summary>
/// Summary description for JobSeeker
/// </summary>
public partial class RecruitVietnam
{

    #region Delete Account
    public bool DeleteJSAccount(
        string userID)
    {
        errorMessage = "";
        bool delete = false;
        try
        {
            SqlServerProvider sqlServerProvider
                = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText =
            "SPDeleteJSAccount";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[1] { "@UserID"};
            sqlServerProvider.ValueCollection =
            new string[1] { userID };
            sqlServerProvider.ExecuteNonQuery();
            sqlServerProvider.CloseConnection();
            delete = true;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return delete;
    }
    #endregion
    
    #region Activate Account
    public bool ActivateJSAccount(       
        string userID,
        string activate)
    {
        errorMessage = "";
        bool save = false;
        try
        {
            SqlServerProvider sqlServerProvider
                = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText =
            "SPJSActivateAccount";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[2] { "@UserID", "@Activate" };
            sqlServerProvider.ValueCollection =
            new string[2] { userID, activate };
            sqlServerProvider.ExecuteNonQuery();
            sqlServerProvider.CloseConnection();
            save = true;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return save;
    }
    #endregion
    
    #region Job Seeker Account
    public int AddNewJSAccount(
        string email, string password,
        string firstName,
        string lastName, string newsletter,
        string jobAlert, string companyInfo)
    {
        errorMessage = "";
        int userID = -1;
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            SecurityProvider securityProvider = 
            new SecurityProvider();
            sqlServerProvider.CommandText = "SPJSAccount";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[8] { "@UserID", "@Email", 
            "@Password", "@FirstName", "@LastName", 
            "@Newsletter", "@JobAlert", 
            "@CompanyInfo" };
            sqlServerProvider.ValueCollection =
            new string[8] { "0", email, 
            securityProvider.RCVEncPwd(password), 
            firstName, lastName, newsletter,
            jobAlert, companyInfo };
            sqlServerProvider.ReturnValueParameter = "@ReturnValue";
            sqlServerProvider.ExecuteNonQuery();
            sqlServerProvider.CloseConnection();
            userID =  sqlServerProvider.ReturnValue;                        
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return userID;
    }
    public bool UpdateJSAccount(string userID,
        string email,
        string firstName,
        string lastName, string newsletter,
        string jobAlert, string companyInfo)
    {
        errorMessage = "";
        bool update = false;
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            SecurityProvider securityProvider =
            new SecurityProvider();
            sqlServerProvider.CommandText = "SPJSAccount";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[8] { "@UserID", "@Email", 
            "@Password", "@FirstName", "@LastName", 
            "@Newsletter", "@JobAlert", 
            "@CompanyInfo" };
            sqlServerProvider.ValueCollection =
            new string[8] { userID, email, "", 
            firstName, lastName, newsletter,
            jobAlert, companyInfo};            
            sqlServerProvider.ExecuteNonQuery();
            sqlServerProvider.CloseConnection();   
            update = true;            
        }

        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return update;
    }
    
    #endregion            
    
    #region Personal Information
    public bool UpdatePersonal(
    string userID,
    string permanent,
    string resident,
    string tel, string mobile,
    short provinceID,
    string city,
    string dob,
    bool gender,
    short maritalStatus,
    short raceID)
    {
        errorMessage = "";
        bool update = false;
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = 
            "SPJSPersonal";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[11] { "@UserID", 
            "@Address", "@Resident", 
            "@Tel", "@Mobile", 
            "@ProvinceID", "@City", 
            "@DOB", "@Gender", 
            "@MaritalStatus", "@RaceID" };
            sqlServerProvider.ValueCollection =
            new string[11] { userID, permanent, 
            resident, tel, mobile, provinceID.ToString(), 
            city, dob, ((gender)?"0":"1") , 
            maritalStatus.ToString(), 
            raceID.ToString()};
            update = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();    
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return update;
    }
    #endregion
              
    #region Education Information
    public bool AddNewOrUpdateEducation(
        string educationID,
        string userID,
        string school,
        string country,
        string faculty,
        string certificate,
        string major,        
        string mode,
        string from, string to,
        string description)
    {
        errorMessage = "";
        bool save = false;
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            
            sqlServerProvider.CommandText = 
            "SPJSEducation";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[11] { "@UserID", 
            "@EducationID", "@School", 
            "@Country", "@Faculty", 
            "@Major", "@Certificate", 
            "@Mode", "@FromMonthYear", 
            "@ToMonthYear", "@Description"};
            sqlServerProvider.ValueCollection =
            new string[11] { userID, educationID, 
            school, country, faculty, major,
            certificate, mode, from, to, description};
            save = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();                                  
            save = true;           
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return save;
    }
    #endregion

    #region Experience Information
    public bool AddNewOrUpdateExperience(
    string experienceID,
    string userID,
    string company,
    string address,
    string province,
    string country,
    string category,
    string summary,
    string position, string salary,
    string from, string to,
    string description)
    {
        errorMessage = "";
        bool save = false;
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            
            sqlServerProvider.CommandText = 
            "SPJSExperience";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[13] { "@UserID", 
            "@ExperienceID", "@Company", 
            "@Address", "@Country", "@ProvinceID",
            "@JobCategoryID", "@JobSummary", 
            "@JobPosition", "@Salary", 
            "@FromMonthYear", 
            "@ToMonthYear", "@Description"};
            sqlServerProvider.ValueCollection =
            new string[13] { userID, experienceID, 
            company, address, country, province, category, 
            summary, position, salary, from, to, description};
            save = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();                                  
            save = true;        
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return save;
    }
     #endregion 
     
    #region Skill Information
    public bool AddNewOrUpdateSkill(
      string skillID,
      string userID,
      string speed,
      string software,
      string vnspeaking,
      string vnreading,
      string vnlistening,
      string enspeaking,
      string enreading,
      string enlistening,
      string description)
    {
        errorMessage = "";
        bool save = false;
        try
        {
            SqlServerProvider sqlServerProvider
                   = new SqlServerProvider(connectionString);
             
            sqlServerProvider.CommandText =
            "SPJSSkill";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[11] { "@UserID", 
            "@SkillID", "@Speed", 
            "@Software", "@VNSpeaking", 
            "@VNReading", "@VNListening", 
            "@ENSpeaking", "@ENReading", 
            "@ENListening", "@Description"};
            sqlServerProvider.ValueCollection =
            new string[11] { userID, skillID, 
            speed, software, vnspeaking, 
            vnreading, vnlistening, 
            enspeaking, enreading, 
            enlistening, description};
            save = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();
            save = true;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return save;
    }
    #endregion

    #region Other Information
    public bool AddNewOrUpdateOthers(
   bool flag,
   string userID,
   string strength,
   string weekness,
   string hobbies,
   string family,
   string reference)
    {
        errorMessage = "";
        bool save = false;
        try
        {
            SqlServerProvider sqlServerProvider
                = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText =
            "SPJSOthers";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[7] { "@Flag", 
            "@UserID", "@Strength", 
            "@Weekness", "@Hobbies", 
            "@Family", "@Reference"};
            sqlServerProvider.ValueCollection =
            new string[7] { ((flag)?"0":"1"), 
            userID, strength, weekness,
            hobbies, family, reference};
            sqlServerProvider.ExecuteNonQuery();
            sqlServerProvider.CloseConnection();
            save = true;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return save;
    }
    #endregion
    
    #region Cover Letter
    public bool AddNewOrUpdateCoverLetter(
        string letterID,
        string userID,
        string subject,
        string body)
    {
        errorMessage = "";
        bool save = false;
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = 
            "SPJSCoverLetter";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[4] { "@UserID", 
            "@LetterID", "@Subject", "@Body" };
            sqlServerProvider.ValueCollection =
            new string[4] { userID, letterID, subject, body };
            save = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();                        
        }
        
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return save;
    }
    #endregion

    #region Saved Search 
    public bool DeleteSavedSearch(
    string userID, string searchID)
    {
        bool deleteItem = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
                = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = 
            "SPDeleteSavedSearch";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[2] { "@UserID", "@SearchID" };
            sqlServerProvider.ValueCollection =
            new string[2] { userID, searchID};
            deleteItem = (
            sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return deleteItem;
    }
    public bool SaveJobSearch(string userID,
    string keyWord, string workLocation,
    string jobCategory, string jobIndustry)
    {
        bool saveJobSearch = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = "SPSaveSearch";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[5] { "@UserID", "@KeyWord", 
            "@WorkLocation", "@JobCategory", "@JobIndustry"};
            sqlServerProvider.ValueCollection =
            new string[5] { userID, keyWord, 
            workLocation, jobCategory, jobIndustry};
            saveJobSearch = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();
        }       
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return saveJobSearch;
    }
    #endregion

    #region Job Alerts
    
    public bool DeleteJobAlert(
    string userID, string alertID)
    {
        bool deleteItem = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
                = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = "SPDeleteJobAlert";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[2] { "@UserID", "@AlertID" };
            sqlServerProvider.ValueCollection =
            new string[2] { userID, alertID };
            deleteItem = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return deleteItem;
    }
    public bool SaveAlert(string alertID, 
    string userID,
    string keyWord, string cityName,
    string jobCategory, string jobIndustry, 
    string receiveEmail, string Schedule)
    {
        bool saveJobSearch = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = "SPSaveJobAlert";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[8] {"@AlertID", "@UserID", "@KeyWord", 
            "@CityName", "@JobCategory", "@JobIndustry", "@Email", "@Schedule"};
            sqlServerProvider.ValueCollection =
            new string[8] {alertID, userID, keyWord, 
            cityName, jobCategory, jobIndustry, receiveEmail, Schedule};
            saveJobSearch = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return saveJobSearch;
    }
    #endregion
    
    #region Applied Job
    public bool DeleteAppliedJob(string deleteQuery)
    {
        bool deleteItem = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
                    = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = deleteQuery;                         
            deleteItem = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();                     
        }         
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return deleteItem;
    }
    public bool ApplyJob(string jobID,
    string resumeID, string coverLetterID)
    {
        bool saveApply = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = 
            "SPApplyJob";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[3] { "@JobID", "@ResumeID", 
            "@CoverLetterID" };
            sqlServerProvider.ValueCollection =
            new string[3] { jobID, resumeID, 
            coverLetterID };
            saveApply = (
            sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return saveApply;
    }
    #endregion

    #region Saved Job
    public bool DeleteSavedJob(string userID, string jobID)    
    {
        bool deleteItem = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = "SPDeleteSavedJob";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[2] { "@UserID", "@JobID" };
            sqlServerProvider.ValueCollection =
            new string[2] { userID, jobID };
            deleteItem = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();             
        }        
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return deleteItem;
    }
        
    public bool SaveJob(string userID, string jobID)
    {
        bool saveJob = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
                = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = "SPSaveJob";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[2] { "@UserID", "@JobID"};
            sqlServerProvider.ValueCollection =
            new string[2] { userID, jobID};
            saveJob = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection(); 
        }        
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return saveJob;
    }

    #endregion

    #region Saved Block Search
    public bool DeleteBlockSearch(string userID, string blockSearchID)
    {
        bool deleteItem = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = "SPDeleteBlockSearch";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[2] { "@UserID", "@BlockSearchID" };
            sqlServerProvider.ValueCollection =
            new string[2] { userID, blockSearchID };
            deleteItem = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return deleteItem;
    }

    public bool SaveBlockSearch(string userID, string recruiterID)
    {
        bool saveJob = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
                = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = "SPSaveBlockSearch";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[2] { "@UserID", "@RecruiterID" };
            sqlServerProvider.ValueCollection =
            new string[2] { userID, recruiterID };
            saveJob = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return saveJob;
    }

    #endregion
    
    #region Send To Friend
    public bool SendJobToFriend(string emailTo, 
    string receiverName, string senderName, 
    string subject, string bodyContent, 
    string jobID, string jobName, string jobCompany)
    {
        bool sendSucessful = false;
        try
        {
            string body  = "Hi, " + 
            receiverName +"<br><br>[";
            body  += senderName + 
            "] has been sent email to intro "+
            "[<a href=\"http://www.recruitvietnam.com/jobseekers/JobDetails.aspx?JobID=" + 
            jobID + "&page=JobResult.aspx\">" + 
            jobName + "</a>] job at "+
            "RecruitVietnam.com of [" + jobCompany + "]to you.";
            body += bodyContent;
            body += "<br>Thanks for using our services.<br>RecruitVietnam Marketing Team.";
            MailProvider mailProvider = new MailProvider();
            sendSucessful = mailProvider.SendMail(emailTo, subject, body);
        }
        catch(Exception ex)
        {
            ErrorMessage = ex.Message;
        }
        return sendSucessful;
    }
    #endregion

}
